﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Web;

namespace HelpWeb
{
    public class ImagesHelp
    {
        public ImagesHelp()
        {
        }

        #region
        XQ.SP.BllServices.BaseTempDataBLL bll = new XQ.SP.BllServices.BaseTempDataBLL();
        public void SetNull(string uid, int FilesTap = 0, int s = 0, int SysTap = 0)
        {
            var items = bll.GetModelList(" UserId=" + uid + " and Status=" + s + " and SysTap=" + SysTap + " and FilesTap=" + FilesTap);
            foreach (var m in items)
            {
                bll.Delete(m.Id);
            }
        }
        public bool SetValue(string str, string uid, int FilesTap = 0, int s = 0, int SysTap = 0)
        {
            var item = new XQ.SP.Model.BaseTempDataItem();
            item.UserId = Int64.Parse(uid);
            item.ImagesPath = str;
            item.Created = DateTime.Now;
            item.Status = s;
            item.SysTap = SysTap;
            item.FilesTap = FilesTap;
            item.Modified = DateTime.Now;

            if (bll.Add(item) > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        public bool AddStr(string str, long uid,int FilesTap=0 , int s = 0, int SysTap=0)
        {
            var item = bll.GetModelWhereStr(" UserId=" + uid + " and Status=" + s + " and SysTap=" + SysTap + " and FilesTap=" + FilesTap);
            if (item == null)
            {
                return SetValue(str, uid.ToString(), s, SysTap, FilesTap);
            }
            else
            {
                item.ImagesPath += str;
                if (bll.Update(item))
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
        }


        public bool DeleteStr(string str, long uid, int FilesTap = 0, int s = 0, int SysTap = 0)
        {
            var item = bll.GetModelWhereStr(" UserId=" + uid + " and Status=" + s + " and SysTap=" + SysTap + " and FilesTap=" + FilesTap);
            item.ImagesPath = item.ImagesPath.Replace(str+"|", "");
            item.ImagesPath = item.ImagesPath.Replace(str, "");
            if (bll.Update(item))
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        public string GetStr(string uid, int FilesTap = 0, int s = 0, int SysTap = 0)
        {
            var item = bll.GetModelWhereStr(" UserId=" + uid + " and Status=" + s + " and SysTap=" + SysTap + " and FilesTap=" + FilesTap);
            return item.ImagesPath;
        }
        #endregion
    }
}
